package com.example.securitytest.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.securitytest.domain.Item;
import com.example.securitytest.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ItemMapper extends BaseMapper<Item>{

    // 根据名字查询
    @Select("SELECT * FROM item WHERE name = #{name}")
    Item selectByName(@Param("name") String name);

    // 根据名字删除
    @Delete("DELETE FROM item WHERE name = #{name}")
    int deleteByName(@Param("name") String name);

    // 根据价格区间查询
    @Select("SELECT * FROM item WHERE price BETWEEN #{minPrice} AND #{maxPrice}")
    List<Item> selectByPriceBetween(@Param("minPrice") double minPrice, @Param("maxPrice") double maxPrice);

    // 批量上传
    @Insert("<script>" +
            "INSERT INTO item (id, name, price, quantity) VALUES " +
            "<foreach collection='items' item='item' separator=','>" +
            "(#{item.id}, #{item.name}, #{item.price}, #{item.quantity})" +
            "</foreach>" +
            "</script>")
    void insertBatchSomeColumn(@Param("items") List<Item> items);
}

